import dataList from '@/components/dataList'
import {fetchList} from "../../api/lessor-payable"
import showActual from "../../lessorpayable/edit/show-actual"
import reviewPayable from '../edit/review-payable'

export default {
    name: "index",
    components: {
        dataList,
        showActual,
        reviewPayable
    },
    provide() {
        return {
            initList: this.getListData,
        };
    },
    beforeMount() {
        this.getListData();
    },
    data() {
        return {
            tableData: [],
            // 请求参数
            params: {
                current: 1,
                size: 20,
                projectName: ''
            },
            // 分页
            pager: {
                total: 0, // 总页数
                current: 1, // 当前页数
                size: 20 // 每页显示多少条
            },
            // 页面loading
            loading: false,
						editPayable: false,
						showPayable: false,
						// 初始化显示状态识别符
						flag: false,
            filterList: [
                { label: '付款项目', inputType: 'dict', dictName: "charge_project_type_lessor", name: 'chargeProjectName', multiple: true},
                { label: '费用周期', inputType: 'date', name: 'costPeriodStart'},
                { label: '状态', inputType: 'dict', dictName: 'payable_status', name: 'payableStatus', multiple: true, defaultValue: ['11']}
            ]
        }
    },
    methods: {
        getListData(params = {}) {
            this.loading = true
						if (!this.flag) params.payableStatus = "11";
            let requestData = {...this.params, ...params}
            fetchList(requestData).then(res => {
								this.flag = true
                const  {current, size, total, records} = res.data.data
                this.tableData = records
                this.params = requestData
                this.pager = {total, current, size}
            }).finally(() => {
                this.loading = false
            })
        },
        //查看
        handleShowReceivableData(row) {
        	this.showPayable = true
					this.$nextTick(() => {
						this.$refs.showActual.show(row)
					})
        },
        //复核
        handleClickSubmit(row) {
        	this.editPayable = true
					this.$nextTick(() =>{
						this.$refs.reviewPayable.show(row)
					})
        },
        //导出
        downloadData(){
            this.publicExport('应付复核','/api/lessorpayable/downloadExcel',this.params)
        },
        // 菜单点击监听
        handleMenuClick(type){
            switch (type) {
                case 'export':
                    this.downloadData();
                    break;
                default:
                    this.$message(type)
                    break;
            }
        },
				// 复核取消销毁
				handleClose() {
					this.editPayable = false
				},
				// 复核确认销毁
				resetList() {
					this.editPayable = false
					this.getListData()
				},
				// 查看销毁
			handleShowClose() {
				this.showPayable = false
			},
    }
}
